<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\ApiController;
use App\Http\Requests\GetCode;
use Illuminate\Http\Request;

class CodeController extends ApiController
{
    /**
     * CodeController constructor.
     */
    public function __construct()
    {}

    /**
     * 获取code
     *
     * @param GetCode $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function getCode(GetCode $request)
    {
        $name = $request->name;

        if (is_array($name)) {
            $map = $name;
        } else {
            $map = explode(',', $name);
        }

        $configArray = [];

        foreach ($map as $value) {
            if ($value) {
                $configArray[$value] = model_code_map($value);
            }
        }

        return $this->success($configArray);
    }

}
